package com.example.sourcecodelearning.controller;

import com.example.framework.common.pojo.R;
import com.example.framework.operatelog.core.annotation.OperationLog;
import com.example.framework.security.core.LoginUser;
import com.example.framework.security.core.annotation.LoggedInUser;
import com.example.framework.security.core.util.SecurityFrameworkUtils;
import com.example.framework.web.annotation.LogRequest;
import com.example.sourcecodelearning.feign.UserFeign;
import com.example.sourcecodelearning.feign.dto.UserInfoRespDto;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Tag(name = "用户接口")
@RestController
@RequestMapping("/user")
@Slf4j
@LogRequest
public class UserController {

    @Resource
    private UserFeign userFeign;

    @OperationLog("通过用户id查询用户信息")
    @Operation(summary = "通过用户id查询用户信息")
    @GetMapping("/getByUserId")
    public R<UserInfoRespDto> getUserByUserId(@RequestParam("userId") String userId) {
        return userFeign.getUserByUserId(userId);
    }

    @Operation(summary = "获取当前登录用户")
    @GetMapping("/getCurrentUser")
    public R<LoginUser> getCurrentUser(@Parameter(hidden = true) @LoggedInUser LoginUser loginUser) {
        log.info("ThreadLocal获取的UserDto: {}", SecurityFrameworkUtils.getLoginUser());
        log.info("参数解析器注入的UserDto: {}", loginUser);
        return R.success(loginUser);
    }

}
